﻿
@{
    ViewBag.Title = "Management";
}
<script src="~/Scripts/jquery.hiMallDatagrid.js"></script>
<style type="text/css">
    .audit_1 { color:#ff6a00; }
    .audit_2 { color:green; }
    .audit_3 { color:red; }
    .audit_4 { color:#666666; }
    .audit_5 { color:#bbbbbb; }
</style>
<div class="container">
    <ul class="nav nav-tabs-custom clearfix">
        <strong>限时购</strong>
        <li class="active"><a>活动管理</a></li>
        @if (ViewBag.Market!= null)
        {
            <li><a href="./AddLimitItem">新增限时购</a></li>
        }
        <li class=""><a href="./BuyService">购买服务</a></li>
        <em class="primary-btn">
            <span class="glyphicon glyphicon-question-sign"></span>
            <div class="primary">
                <h3>温馨提示：</h3>
                <span>*</span><p>显示店铺已经申请的限时购活动列表</p>
            </div>
        </em>
    </ul>
    @if (ViewBag.Market == null)
    {
		<div class="form-horizontal">
			<div class="form-group">
				<p class="apply-primary"><span class="glyphicon glyphicon-info-sign"></span>您还未购买限时购服务或者服务已到期，<a href="./BuyService">现在购买</a></p>
			</div>
		</div>
    }
    else
    {

        @*<div class="table-top">
            <a  id="AddItem" class="btn btn-primary btn-ssm"><span class="glyphicon glyphicon-plus-sign"></span>&nbsp; 添加活动</a>
        </div>*@
        <div>
            <table class="table" id="list"></table>
        </div>
    }
</div>

<script type="text/javascript">
    $(function () {

        $('#searchButton').click(function (e) {
            searchClose(e);
            var shopName = $.trim($('#txtShopName').val());
            $("#list").hiMallDatagrid('reload',
                {
                    shopName: shopName,
                });
        });

            //订单表格
            $("#list").hiMallDatagrid({
                url: './GetItemList',
                nowrap: false,
                rownumbers: true,
                NoDataMsg: '没有找到符合条件的限时购活动',
                border: false,
                fit: true,
                fitColumns: true,
                pagination: true,
                idField: "Id",
                pageSize: 15,
                pagePosition: 'bottom',
                pageNumber: 1,
                queryParams: {},
                columns:
                [[
                    { field: "Id", title: 'Id', hidden: true, width: 150 },
                    { field: "ProductId", title: 'ProductId', hidden: true, width: 150 },
                    {
                        field: "ProductName", title: "商品名称",align: "left",
                        formatter: function (value, row, index) {
                            var html = '<span class="overflow-ellipsis" style="width:200px"><a title="' + value + '" href="/product/detail/' + row.ProductId + '" target="_blank">' + value + '</a></span>';
                            return html;
                        }
                    },
                    { field: "StartTime", title: "开始时间", width: 150, align: "center" },
                    { field: "EndTime", title: "结束时间", width: 150, align: "center" },
            { field: "MaxSaleCount", title: "限购数", width: 60, align: "center" },
                    { field: "SaleCount", title: "销售数", width: 60, align: "center" },
                   {
                       field: "AuditStatus", title: "审核状态", width: 80, align: "center",
                       formatter: function (value, row, index) {
                           var html = '<span class="audit_' + row.AuditStatusNum + '">' + value + '</span>';
                           return html;
                       }
                   },
                {
                    field: "CancelReson", title: "平台审批",width:100,
                    formatter: function (value, row, index) {
                        var html = "<a href=\"javascript:showReason('" + value + "')\" >" + (value ? "查看意见" : "") + "</a>";
                        return html;
                    }
                },
                {
                    field: "operation", operation: true,width:150, title: "操作",
                    formatter: function (value, row, index) {
                        var id = row.Id.toString();
                        var html = ["<span class=\"btn-a\">"];
                        if (row.AuditStatus == "待审核") {
                            html.push("<a class=\"good-check\" href=\"./EditLimitItem/" + id + "\">编辑</a>");
                        }
                        html.push("<a class=\"good-check\" onclick=\"copyurl('\/LimitTimeBuy\/Detail\/" + id + "')\">复制链接</a>");
                        html.push("</span>");
                        return html.join("");
                    }
                }
                ]]
            });
        $("#AddItem").click(function () {
            location.href = "./AddLimitItem";
        });
    });

    function copyurl(url) {
        url = window.location.protocol + "//" + window.location.host + url;
        $.dialog({
            title: '专题链接',
            lock: true,
            id: 'copydlg',
            content: ['<div class="dialog-form">',
                '<div class="form-group">',
                    '<input type="text" id="txturl" value="' + url + '" class="form-control" style="width:300px"/>',
                '</div>',
            '</div>'].join(''),
            padding: '10px',
            init: function () { $("#txturl").focus(); }
        });
    }

    function showReason(msg) {
        $.dialog({
            title: '平台审批意见',
            lock: true,
            id: 'preasondlg',
            content: ['<div class="dialog-form">',
                '<div class="form-group">',
                    msg,
                '</div>',
            '</div>'].join(''),
            padding: '10px'
        });
    }
</script>